#!/usr/bin/env bash

mvn clean package -DskipTests -Pprod

#docker build . -t hb/manage-api:latest

# shellcheck disable=SC2006
#docker_bridge_gateway=`/sbin/ip route | awk '/docker0/ {printf $NF}'`

docker_container=supervision-manage-api
docker_image=di.wwhis.com:5000/notary/notary-api:latest
port=9101:80
#host1=db:$docker_bridge_gateway
#host2=redis:$docker_bridge_gateway

app_path=/opt/app/supervision-api/manage-api
volume=$app_path:/opt/java
log_volume=/opt/logs/supervision-api:/tmp/logs

rm -rf $app_path
mkdir -p $app_path

rsync -az -t "./target/manage-api-1.0.0.jar" "$app_path/app.jar"

docker rm -f ${docker_container}
docker run -d --restart=always \
            -p ${port} \
            -v $volume \
            -v $log_volume \
            --log-opt max-size=1000m \
            --name=${docker_container} \
            ${docker_image}

docker logs -f ${docker_container}